import QtQuick
import QtQuick.Controls

Page {
    title: "网络图片加载"
    
    Rectangle {
        anchors.fill: parent
        color: "#f0f0f0"
        
        Column {
            anchors.centerIn: parent
            spacing: 10
            
            Image {
                width: 400
                height: 300
                source: "https://doc.qt.io/qt-6/images/qtquickcontrols-styles.png"
                asynchronous: true  // 推荐网络加载使用异步
                
                BusyIndicator {
                    anchors.centerIn: parent
                    running: parent.status === Image.Loading
                }
                
                Text {
                    anchors.centerIn: parent
                    visible: parent.status === Image.Error
                    text: "加载失败\n" + parent.errorString
                    color: "red"
                    horizontalAlignment: Text.AlignHCenter
                }
            }
            
            Text {
                text: "状态: " + getStatusText(parent.children[0].status)
                
                function getStatusText(status) {
                    switch(status) {
                        case Image.Ready: return "加载完成"
                        case Image.Loading: return "加载中..."
                        case Image.Error: return "加载失败"
                        default: return "未知状态"
                    }
                }
            }
        }
    }
} 
